Threads , also known as lightweight tasks , are a way to develop concurrency, or multiple points of execution, within a particular context, such as in an operating system or application. The Thread Manager offers threads for use within an application context only. It does not provide threads to be used on a systemwide basis.
Threads offer a new and better way to structure applications for simplicity, efficiency, and responsiveness. With multiple points of execution, you can do things such as
Although you can already do many of the things that threads enable you to do, the implementation without threads can be difficult and inelegant. For example, with null events at idle time you can write idle-processing procedures that bring a measure of concurrency to your application. However, threads offer many advantages not available with other methods of achieving concurrency in an application program.
A major benefit of using threads is that you can enhance the logical structure of your program. Using threads is in many ways like adding an object layer to your program. For example, one way to write a traffic simulation program is to create a separate thread to control each element of the simulation--that is, the traffic signals and the individual cars. You could think of each thread as an object with particular capabilities. In any case, programs with threads are easier to write and much easier to understand than programs that achieve concurrency in a roundabout fashion, such as using idle-processing procedures or state machines.
A thread consists of application code and the processor state or context to execute it. The thread context consists of a register set, a program counter, and a stack. Each thread shares the address space, file access paths, and other system resources of the application process in which it runs. Therefore, when the Thread Manager switches control from one thread to another, the amount of context information it must save is relatively small and the switch is much faster than that between application processes.